<?php

class ClassesController extends GxController {

    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('viewClass', 'CompareclassAddClassById', 'classcategory', 'search', 'view', 'literalendingtommorow', 'workshopcourses'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('create', 'setAuthKey', 'update', 'StarRatingAjax', 'manageclasses', 'admin'),
                'users' => array('@'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    public function actionview() {
        $this->render('view');
    }

//    public function actionindex() {
//        $model = Classes::model()->findAll();
//
//        foreach ($model as $models) {
//            $search = array(' ', '&');
//            $replace = array('-', 'and');
//            $str = trim(strtolower(str_replace($search, $replace, $models->class_titile)));
//            Classes::model()->updateByPk($models->id, array('class_seo_title' => $str));
//        }
//    }

    public function actionCreate() {
        $model = new Classes;
        $modelFunLearning = new FunLearning;
        Yii::app()->user->setState('authKey', NULL);
        $authKey = time() . guid();
        if (isset($_POST['Classes'])) {
            $classtags = '';
            $classTagText = '';
            if (!empty($_POST['Classes']['class_tag'])) {
                foreach ($_POST['Classes']['class_tag'] as $key => $value) {
                    $classTag = ClassCourseTags::model()->findByPk($value);
                    $classTagText .=$classTag->tag_name . ',';
                    $classtags.=$value . ',';
                }
            }
            $model->attributes = $_POST['Classes'];
            $search = array(' ', '&');
            $replace = array('-', 'and');
            $seo_title = trim(strtolower(str_replace($search, $replace, $_POST['Classes']['class_titile'])));
            $model->setAttribute('class_seo_title', $seo_title);
            $model->setAttribute('create_time', SkillConfig::CreateDateTime());
            $model->setAttribute('status', SkillConfig::STATUS_DEACTIVE);
            $model->setAttribute('class_type_id', LEAD_CLASS_TYPE);
            $valid = $model->validate();
            if ($valid) {
                $model->setAttributes($_REQUEST['Classes']);
                $model->setattribute('class_tag', $classtags);
                $model->setAttribute('class_tag_description', $classTagText);
                $model->setAttribute('users_id', getLoginUserId());
                $model->setAttribute('auth_key', $authKey);

                if ($model->save(false)) {
                    if (!empty($_POST['ClassCourseTags']['tag_name'])) {
                        $this->saveClassSuggestTag($_POST['ClassCourseTags']['tag_name']);
                    }
                    self::saveClassFunLearning($model);
                    self::saveClassTargetAudience($model);
                    Yii::app()->user->setState('authKey', $model->auth_key);
                    $this->redirect(array('ClassVenue/Classvenue'));
                }
            }
        }

        $this->render('create', array('model' => $model, 'modelFunLearning' => $modelFunLearning));
    }

    public function actionUpdate() {
        $authKey = Yii::app()->user->getState('authKey');
        $modelFunLearning = new FunLearning;
        if (!empty($authKey)) {
            $classtags = '';
            $classTagText = '';
            if (!empty($_POST['Classes']['class_tag'])) {
                foreach ($_POST['Classes']['class_tag'] as $key => $value) {
                    $classTag = ClassCourseTags::model()->findByPk($value);
                    $classTagText .=$classTag->tag_name . ',';
                    $classtags.=$value . ',';
                }
            }
            $classes = Classes::model()->findByAttributes(array('auth_key' => $authKey));
            $model = $this->loadModel($classes->id, 'Classes');
            $FunLearning = $modelFunLearning->findByAttributes(array('classes_id' => $classes->id));
            if (count($FunLearning) > 0) {
                $modelFunLearning = $FunLearning;
            }
            $model->setAttribute('update_time', SkillConfig::CreateDateTime());
            $search = array(' ', '&');
            $replace = array('-', 'and');

            if (getLoginUserId() == $model->users_id) {
                if (isset($_POST['Classes'])) {
                    $seo_title = trim(strtolower(str_replace($search, $replace, $_POST['Classes']['class_titile'])));
                    $model->setAttribute('class_seo_title', $seo_title);
                    $model->setAttributes($_POST['Classes']);
                    $model->setattribute('class_tag', $classtags);
                    $model->setAttribute('class_tag_description', $classTagText);
                    if ($model->save()) {
                        if (!empty($_POST['ClassCourseTags']['tag_name'])) {
                            $this->saveClassSuggestTag($_POST['ClassCourseTags']['tag_name']);
                        }
                        self::saveClassFunLearning($model);
                        self::saveClassTargetAudience($model);
                        Yii::app()->user->setState('authKey', $model->auth_key);
                        $this->redirect(array('ClassVenue/Classvenue'));
                    }
                }
                $this->render('update', array('model' => $model, 'modelFunLearning' => $modelFunLearning));
            }
        } else {
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
        }
    }

    private static function saveClassFunLearning($model) {
        (!$model->isNewRecord) ? Classes::deleteClassFunLearning($model->id) : '';
        $modelFunLearning = new FunLearning;
        if (isset($_POST['FunLearningValue'])) {
            $fun = $_POST['FunLearningValue']['fun'];
            $learn = SkillConfig::FUN_LEARING_LIMIT - $fun;
            $modelFunLearning->setAttribute('fun', $fun);
            $modelFunLearning->setAttribute('learn', $learn);
            $modelFunLearning->setAttribute('classes_id', $model->id);
            $modelFunLearning->setAttribute('status', 1);
            $modelFunLearning->setAttribute('create_time', SkillConfig::CreateDateTime());
            $modelFunLearning->save(FALSE);
        }
    }

    private static function saveClassTargetAudience($model) {
        (!$model->isNewRecord) ? Classes::deleteClassesTargetAudience($model->id) : '';
        if (isset($_POST['Classes']['classesTargetAudiences']) && !empty($_POST['Classes']['classesTargetAudiences'])) {
            foreach ($_POST['Classes']['classesTargetAudiences'] as $targetAudience) {
                $modelClassTargetAudience = new ClassesTargetAudience();
                $modelClassTargetAudience->target_audience_id = $targetAudience;
                $modelClassTargetAudience->classes_id = $model->id;
                $modelClassTargetAudience->save(false);
            }
        }
    }

    public function actionsetAuthKey() {
        Yii::app()->user->setState('authKey', NULL);
        $authKey = $_POST['authKey'];
        Yii::app()->user->setState('authKey', $authKey);
        echo $this->createAbsoluteUrl($_POST['action']);
    }

    public function actionviewClass($id, $class_seo_title) {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $classTag = '';
        $discount = '';
        $priceRange = '';
        $classTrainerRate = '';
        $classtotalCountTrainerate = '';
        $vanueId = '';
        $levelType = '';
        $model = Classes::model()->findByAttributes(array('id' => $id, 'class_seo_title' => $class_seo_title));
        $userModel = new Users;
        $SundayContestmodel = new SundayContest;
        $renderPage = ($id == 212) ? 'sunday_contest' : '_viewClass';
        $userId = getLoginUserId();
        if (!empty($model) AND ( $model->status == 1 OR $userId == $model->users_id)) {
            $this->pageTitle = SITE_TITLE . ' | ' . $model->class_titile;
            Yii::app()->clientScript->registerMetaTag(strip_tags($model->class_short_description), 'description');
            Yii::app()->clientScript->registerMetaTag($model->class_tag_description, 'keywords');
            Yii::app()->clientScript->registerMetaTag($this->createAbsoluteUrl('/workshop-' . $model->id . '/' . $model['class_seo_title']), '', null, array('id' => 'meta-url', 'property' => 'og:image'), 'meta_og_image');
            $makeQueryModel = new MakeQuery;
            $timingMakequeryModel = new TimingMakequery;
            $booknow = ($model->class_type_id == CURATED_CLASS_TYPE) ? 'Book Now' : Message::MAKE_QUERY;
            $discount = ClassEarlyDiscount::findMaxDscountByClass($model->id);
            $priceRange = ClassBatch::findMinMaxPriceByClassbatch($model->id);
            $levelType = classCourseLevelType('Classes', $model->id);
            $funLearing = Classes::getfunlearing($model->id);
            $cssLevel = LevelCssClassName('Classes', $model->id);
            $seats = ClassBatch::seatsAvalableClass($model);
            $classTag = ClassCourseTags::getClassCourseTag($model->class_tag);
            $userType = ($model->users_id == '') ? 'backend' : 'front-end';
            $classTrainerRate = Classes::trainerPossitiverate($userType, $model);
            $classtotalCountTrainerate = Classes::trainertotalRate($userType, $model);
            $userDetails = ($model->users_id == '') ? Users::getBackEndUser($model->backend_user_id) : Users::getFrontEndUser($model->users_id);
            $imagePath = ($model->users_id == '') ? 'backend/' . $model->backend_user_id : $model->users_id;
            /* --------------------find all venue name by classid start---------------------- */
            $batchdateTime = ClassBatch::getAllbatchByClass($model->id, '');
            $venueDetails = ClassBatch::getVenueListBox($batchdateTime, '');
            $batchStartDateList = ClassBatch::classBatchstartDateList($batchdateTime);
            $batchStartTimeList = ClassBatch::classBatchstartTimeList($batchdateTime);
            $batchseatList = ClassBatch::classBatchseatsList($batchdateTime);
            $batchId = ClassBatch::getbatchIdonviewDeatls($batchdateTime);

            /* --------------------find all venue name by classid end---------------------- */

            /* Check session of comapre class couese */
            if (Yii::app()->session['compare_type'] = "class" && Yii::app()->session['allcompare_ids'] <> "") {
                $compare_class_course_id = Yii::app()->session['allcompare_ids'];
                $checkIds = rtrim($compare_class_course_id, ',');
                $checkIds = explode(',', $checkIds);
                if (count($checkIds) > 0) {
                    $compareIds = $checkIds;
                }
            } else {
                $compareIds = array();
            }


            /* End Check session of comapre class couese */

            $this->render($renderPage, array('userModel' => $userModel, 'cssLevel' => $cssLevel, 'batchId' => $batchId, 'batchStartDateList' => $batchStartDateList, 'batchStartTimeList' => $batchStartTimeList,
                'batchseatList' => $batchseatList, 'SundayContestmodel' => $SundayContestmodel,
                'model' => $model, 'booknow' => $booknow, 'classTag' => $classTag, 'userDetails' => $userDetails, 'venueDetails' => $venueDetails, 'discount' => $discount,
                'priceRange' => $priceRange, 'imagePath' => $imagePath, 'funLearing' => $funLearing, 'makeQueryModel' => $makeQueryModel, 'timingMakequeryModel' => $timingMakequeryModel, 'userType' => $userType,
                'classTrainerRate' => $classTrainerRate, 'classtotalCountTrainerate' => $classtotalCountTrainerate, 'compareIds' => $compareIds, 'levelType' => $levelType, 'seats' => $seats
            ));
        } elseif (!empty($model) AND ( $model->status == 0)) {
            throw new CHttpException(400, Yii::t('app', Message::EXCEPTION_NOT_ACTIVATE_CLASS));
        } else
            throw new CHttpException(400, Yii::t('app', Message::EXCEPTION_NOT_ACTIVATE_CLASS));
    }

    public function actionStarRatingAjax() {
        $ratingAjax = isset($_POST['rate']) ? $_POST['rate'] : 0;
        echo $ratingAjax;
    }

    public function actionmanageClasses($location = '', $classType = '', $courseClass = '') {
        $this->layout = FALSE;
        $courseData = array();
        $classData = array();
        $classVenueVals = ClassVenue::model()->findAll('users_id=' . getLoginUserId());
        if ($courseClass == 2) {
            $courseData = manageCourseByuser($classType, $location);
        } elseif ($courseClass == 1) {
            $classData = manageClassByuser($classType, $location);
        } else {
            $classData = manageClassByuser($classType, $location);
            $courseData = manageCourseByuser($classType, $location);
        }
        $classCoursedataprovider = array_merge($classData, $courseData);
        $dataProvider = new CArrayDataProvider($classCoursedataprovider, array(
            'sort' => array(
                'attributes' => array(
                    'status',
                ),
            ),
            'pagination' => array(
                'pageSize' => 9,
            ),
        ));

        $this->render('manageClasses', array(
            'dataProvider' => $dataProvider, 'classVenueVals' => $classVenueVals
        ));
    }

    public function actionCompareclassAddClassById() {
        $classDetail = Classes::model()->findByPk($_POST['classid']);
        $class_titile = $classDetail->class_titile;
        $imagePath = ($classDetail->users_id == '') ? 'backend/' . $classDetail->backend_user_id : $classDetail->users_id;
        if (ClassImage::getPrimaryImage($classDetail->id) <> "") {
            $classImg = '<img src="' . getRequestbaseUrl() . getuploadFolderDir() . SkillConfig::getClassCourseImagePath($imagePath) . 'thumbs/' . ClassImage::getPrimaryImage($classDetail->id) . '"  alt="' . $classDetail->class_titile . '">';
        } else {
            $classImg = '<img src="' . getRequestbaseUrl() . getuploadFolderDir() . getWorkNoshopimage(SkillConfig::skill_myinbox_image) . '" height="70" width="70"  alt="' . $classDetail->class_titile . '">';
        }
        echo $return_data = $class_titile . '#@#' . $classImg;
    }

    protected function saveClassSuggestTag($suggestTagVal) {
        $suggestTagVals = explode(',', $suggestTagVal);
        foreach ($suggestTagVals as $suggestTagVal) {
            $classCoursetag = new ClassCourseTags();
            $classCoursetag->setAttribute('tag_name', $suggestTagVal);
            $classCoursetag->setAttribute('create_time', SkillConfig::CreateDateTime());
            $classCoursetag->setAttribute('status', SkillConfig::STATUS_DEACTIVE);
            $classCoursetag->setAttribute('users_id', getLoginUserId());
            $classCoursetag->save(false);
        }
    }

    public function actionclassCategory() {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $activeClass = '';
        $date = date('Y-m-d');
        $criteria = new CDbCriteria();
        $type = isset($_GET['type']) ? $_GET['type'] : $_GET['name'];
        $activeClass = activeClassCategory($type);
        if (!empty($activeClass)) {
            $classTypes = ClassType::model()->findAll('status=' . SkillConfig::STATUS_ACTIVE);
            /* this code use for course */
            if ($activeClass[1] == 'course') {
                if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                    $coursesArray = runningCurrentCoursesByUser('', '', $_GET);
                } else {
                    $coursesArray = runningCurrentCoursesByUser('', '', $_GET);
                }
                $dataProvider = new CArrayDataProvider($coursesArray, array(
                    'sort' => array(
                        'attributes' => array(
                            'start_date',
                        ),
                    ),
                    'pagination' => array(
                        'pageSize' => 9,
                    ),
                ));
            }
            /* this code use for class */
            if ($activeClass[1] == 'workshop' || $activeClass[1] == 'curatedclasses' || $activeClass[1] == 'exclusives') {
                if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                    $classWorkShoparray = literalEndingTommorow('', '', $_GET);
                    /* 1=>ascending,2=>desending */
                    $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                    usort($classWorkShoparray, $comapreFunction);
                } else {
                    $curatedArray = (!empty($type)) ? array('type' => $type) : $_GET;
                    $classWorkShoparray = literalEndingTommorow('', '', $curatedArray);
                    usort($classWorkShoparray, 'date_compare');
                }
                $dataProvider = new CArrayDataProvider($classWorkShoparray, array(
                    'sort' => array(
                        'attributes' => array(
                            'start_date',
                        ),
                    ),
                    'pagination' => array(
                        'pageSize' => 9,
                    ),
                ));
            }

            $this->render('_classCategory', array('classTypes' => $classTypes,
                'activeClass' => $activeClass, 'dataProvider' => $dataProvider));
        } else
            throw new CHttpException(400, Yii::t('app', Message::Invalid_Request));
    }

    public function actionliteralendingtommorow() {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $pagetype = 'LiterallyEndingClasses';
        $allClassCourseInfo = array();
        if (isset($_GET['type']) && $_GET['type'] == 'course') {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {

                $allClassCourseInfo = getAllliteralEndingTommorowCourses('', '', $_GET, '');
                if (!empty($_GET['priceorder']) OR ! empty($_GET['mostpopular'])) {
                    $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                    usort($allClassCourseInfo, $comapreFunction);
                }
            } else {
                $allClassCourseInfo = getAllliteralEndingTommorowCourses('', '', $_GET, '');
            }
        } elseif (isset($_GET['type']) && ($_GET['type'] == 'workshop' OR $_GET['type'] == 'curatedclasses')) {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = getAllliteralEndingTommorowWorkshop('', '', $_GET, '');
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = getAllliteralEndingTommorowWorkshop('', '', $_GET, '');
            }
        } else {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $classDetails = getAllliteralEndingTommorowWorkshop('', '', $_GET, '');
                $courseDetails = getAllliteralEndingTommorowCourses('', '', $_GET, ''); //Null parameter means these value $profiles, $userType, $getValue)
                $allClassCourseInfo = array_merge($classDetails, $courseDetails);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $classDetails = getAllliteralEndingTommorowWorkshop('', '', $_GET, '');
                $courseDetails = getAllliteralEndingTommorowCourses('', '', $_GET, ''); //Null parameter means these value $profiles, $userType, $getValue)
                $allClassCourseInfo = array_merge($classDetails, $courseDetails);
                usort($allClassCourseInfo, 'date_compare');
            }
        }


        if (isset($_GET)) {
            $dataProvider = new CArrayDataProvider($allClassCourseInfo, array(
                'sort' => array(
                    'attributes' => array(
                        'start_date',
                    ),
                ),
                'pagination' => array(
                    'pageSize' => 9,
                ),
            ));

            $this->render('_litterallyEndingdView', array('dataProvider' => $dataProvider, 'pagetype' => $pagetype));
        } else
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
    }

    public function actionsearch() {
        $cs = Yii::app()->clientScript;
        $locationval = '';
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $allClassCourseInfo = array();
        if (isset($_GET['type']) && $_GET['type'] == 'course') {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
            }
        } elseif (isset($_GET['type']) && ($_GET['type'] == 'workshop' OR $_GET['type'] == 'curatedclasses')) {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
            }
        } else {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $classDetails = literalEndingTommorow('', '', $_GET);
                $courseDetails = runningCurrentCoursesByUser('', '', $_GET); //Null parameter means these value $profiles, $userType, $getValue)
                $allClassCourseInfo = array_merge($classDetails, $courseDetails);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                if (isset($_GET['location'])) {
                    $locationval = $_GET['location'];
                    $classDetails = literalEndingTommorow('', '', $_GET);
                    $courseDetails = runningCurrentCoursesByUser('', '', $_GET); //Null parameter means these value $profiles, $userType, $getValue)
                    $classDetails = array_map('unserialize', array_unique(array_map('serialize', $classDetails)));
                    $allClassCourseInfo = array_merge($courseDetails, $classDetails);
                }
            }
        }
        $dataProvider = new CArrayDataProvider($allClassCourseInfo, array(
            'sort' => array(
                'attributes' => array(
                    'start_date',
                ),
            ),
            'pagination' => array(
                'pageSize' => 9,
            ),
        ));
        $this->render('search_class_Course', array('dataProvider' => $dataProvider, 'locationval' => $locationval));
    }

    public function actionworkshopcourses() {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $allClassCourseInfo = array();
        if (isset($_GET['type']) && $_GET['type'] == 'course') {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                usort($allClassCourseInfo, 'date_compare');
            }
        } elseif (isset($_GET['type']) && ($_GET['type'] == 'workshop' OR $_GET['type'] == 'curatedclasses')) {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
            }
        } else {
            //this condion for search weekend clascourse
            if (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_WEEKEND) {
                $searchtype = array('scheduleId' => SEARCH_CLASS_WEEKEND_SET_DAY_SESSION);
            }
            if (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_KIDS) {
                $searchtype = array('searchtype' => SEARCH_TYPE_KIDS);
            }
            if (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_POST_WORK) {
                $searchtype = array('postwork' => SEARCH_CLASS_POST_WORK_SET_START_TIME);
            }
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $classDetails = literalEndingTommorow('', '', $_GET);
                $courseDetails = runningCurrentCoursesByUser('', '', $_GET); //Null parameter means these value $profiles, $userType, $getValue)
                $allClassCourseInfo = array_merge($classDetails, $courseDetails);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $classDetails = literalEndingTommorow('', '', $searchtype);
                $courseDetails = runningCurrentCoursesByUser('', '', $searchtype); //Null parameter means these value $profiles, $userType, $getValue)
                $classDetails = array_map('unserialize', array_unique(array_map('serialize', $classDetails)));
                $allClassCourseInfo = array_merge($courseDetails, $classDetails);
                //usort($allClassCourseInfo, 'date_compare');
            }
        }
        $dataProvider = new CArrayDataProvider($allClassCourseInfo, array(
            'sort' => array(
                'attributes' => array(
                    'start_date',
                ),
            ),
            'pagination' => array(
                'pageSize' => 9,
            ),
        ));
        $this->render('_workshopcourses', array('dataProvider' => $dataProvider,));
    }

}
